package Eyjafjalla.card.skill;

import Eyjafjalla.action.ChorusAction;
import Eyjafjalla.action.MelodyAction;
import Eyjafjalla.card.AbstractEyjafjallaCard;
import Eyjafjalla.patch.MelodyPatch;
import Eyjafjalla.power.WhiteCloudPower;
import Eyjafjalla.subscriber.MelodySubscriber;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.HealAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

import java.util.ArrayList;

public class BlazePrelude_Eyjafjalla extends AbstractEyjafjallaCard implements MelodySubscriber {
    public static final String ID = "BlazePrelude_Eyjafjalla";
    private static final CardStrings cardStrings;

    public BlazePrelude_Eyjafjalla(){
        super(ID, cardStrings.NAME,0,cardStrings.DESCRIPTION,CardType.SKILL,CardRarity.RARE,CardTarget.NONE);
        setFireDescription(cardStrings.EXTENDED_DESCRIPTION[0]);
        this.exhaust = true;
        this.baseMagicNumber = 1;
        this.magicNumber = 1;
    }

    @Override
    public AbstractCard makeCopy() {
        return new BlazePrelude_Eyjafjalla();
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new MelodyAction(getSingle()));
    }

    public MelodyPatch.MelodySingle getSingle(){
        ArrayList<MelodyPatch.MelodyNote> notes = new ArrayList<>();
        String des = (isFire()?cardStrings.EXTENDED_DESCRIPTION[2]:cardStrings.EXTENDED_DESCRIPTION[1]) + this.magicNumber + cardStrings.EXTENDED_DESCRIPTION[3];
        notes.add(new MelodyPatch.MelodyNote(this,0,2,des));
        notes.add(new MelodyPatch.MelodyNote(this,1,2,des));
        notes.add(new MelodyPatch.MelodyNote(this,2,2,des));
        notes.add(new MelodyPatch.MelodyNote(this,3,2,des));
        notes.add(new MelodyPatch.MelodyNote(this,4,1,des));
        MelodyPatch.MelodySingle single = new MelodyPatch.MelodySingle(this.name,notes,null);
        return single;
    }

    @Override
    public ArrayList<AbstractGameAction> getNoteActions(boolean isFinal, int specialAmount) {
        ArrayList<AbstractGameAction> actions = new ArrayList<>();
        boolean fire = specialAmount<0;
        int magic = Math.abs(specialAmount);
        actions.add(new ChorusAction(magic,false,0,true));
        if(fire){
            actions.add(new ChorusAction(magic,false,0,false));
        }
        return actions;
    }

    //若为负数，表示炎息状态
    @Override
    public int initializeSpecialAmount(boolean isFinal) {
        return isFire()?(-this.magicNumber):this.magicNumber;
    }

    @Override
    public void upgrade() {
        if(!this.upgraded){
            upgradeName();
            upgradeMagicNumber(1);
        }
    }

    static {
        cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    }
}


